package com.kuhyygy.async;

import android.os.AsyncTask;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

public class DownloadAsyncTask extends AsyncTask<Integer, Integer, String> {
	
	private TextView tv ;
	private ProgressBar pb;
	
	public DownloadAsyncTask(TextView tv, ProgressBar pb) {
		super();
		this.tv = tv;
		this.pb = pb;
	}

	@Override
	protected String doInBackground(Integer... arg0) {
		for (int i = 10; i <= 100; i += 10) {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			publishProgress(i);
		}
		return arg0[0] + "";
	}

	@Override
	protected void onPostExecute(String result) {
		System.out.println("异步任务执行完毕:" + result);
		tv.setText("异步任务执行完毕" + result);
		pb.setVisibility(View.GONE);
	}

	@Override
	protected void onPreExecute() {
		System.out.println("开始执行异步任务...");
	}

	@Override
	protected void onProgressUpdate(Integer... values) {
		pb.setProgress(values[0].intValue());
		tv.setText("当前进度:" + values[0]);
		System.out.println("当前进度:" + values[0]);
	}

	
}
